package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.CustomerProblem;
import com.isunland.managesystem.entity.DataStatus;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/2/23 10:28
 */
public class CustomerProblemDetailFragment extends Fragment {
  protected static final String EXTRA_CONTENT =
      "com.isunland.managesystem.ui.CustomerProblemDetailFragment.EXTRA_CONTENT";
  @BindView(R.id.tv_customerName) TextView tvCustomerName;
  @BindView(R.id.tv_constractName) TextView tvConstractName;
  @BindView(R.id.tv_reportDesc) TextView tvReportDesc;
  @BindView(R.id.tv_reportName) TextView tvReportName;
  @BindView(R.id.tv_reportDate) TextView tvReportDate;
  @BindView(R.id.tv_reportPhone) TextView tvReportPhone;
  @BindView(R.id.tv_reportAddress) TextView tvReportAddress;
  @BindView(R.id.tv_reportType) TextView tvReportType;
  @BindView(R.id.tv_questionType) TextView tvQuestionType;
  @BindView(R.id.tv_questionLevel) TextView tvQuestionLevel;
  @BindView(R.id.tv_dispatchStaffName) TextView tvDispatchStaffName;
  @BindView(R.id.tv_specifyHandlerName) TextView tvSpecifyHandlerName;
  @BindView(R.id.tv_handleDemand) TextView tvHandleDemand;
  @BindView(R.id.tv_titleRight) TextView tvDataStatus;
  @BindView(R.id.tv_ifEnd) TextView tvIfEnd;
  @BindView(R.id.tv_dealManName) TextView tvDealManName;
  @BindView(R.id.tv_dealTime) TextView tvDealTime;
  @BindView(R.id.tv_dealDesc) TextView tvDealDesc;
  @BindView(R.id.tv_appealStaffName) TextView tvAppealStaffName;
  @BindView(R.id.tv_appealRegDate) TextView tvAppealRegDate;

  private CustomerProblem mContent;

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    ActionBar actionBar = ((BaseVolleyActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {
      actionBar.setDisplayHomeAsUpEnabled(true);
      actionBar.setTitle(R.string.customer_problem);
    }
    mContent = (CustomerProblem) getArguments().getSerializable(EXTRA_CONTENT);
  }

  @Nullable @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_customer_problem, container, false);
    ButterKnife.bind(this, view);
    bindData();
    return view;
  }

  private void bindData() {
    tvCustomerName.setText(mContent.getCustomerName());
    tvConstractName.setText(mContent.getContractName());
    tvReportDesc.setText(mContent.getReportDesc());
    tvReportName.setText(mContent.getReportName());
    tvReportDate.setText(mContent.getRegTime());
    tvReportPhone.setText(mContent.getReportPhone());
    tvReportAddress.setText(mContent.getReportAddress());
    tvReportType.setText(mContent.getComplainFault());//申报类型
    tvQuestionType.setText(mContent.getQuestionType());
    tvQuestionLevel.setText(mContent.getQuestionLevel());
    tvDispatchStaffName.setText(mContent.getDispatchStaffName());
    tvSpecifyHandlerName.setText(mContent.getSpecifyHandlerName());
    tvHandleDemand.setText(mContent.getHandleDemand());
    tvDataStatus.setText(DataStatus.getDataStatusName(mContent.getDataStatus()));
    if ("T".equalsIgnoreCase(mContent.getIfEnd())) {
      tvIfEnd.setText("是");
    } else {
      tvIfEnd.setText("否");
    }
    tvDealManName.setText(mContent.getDealManName());
    tvDealTime.setText(mContent.getDealTime());
    tvDealDesc.setText(mContent.getDealDesc());
    tvAppealStaffName.setText(mContent.getRegStaffName());
    tvAppealRegDate.setText(mContent.getRegDate());
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }

  public static CustomerProblemDetailFragment newInstance(CustomerProblem content) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_CONTENT, content);
    CustomerProblemDetailFragment fragment = new CustomerProblemDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
